package com.glory.brepda.activity.lanjian;


import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.glory.brepda.R;
import com.glory.brepda.activity.technicalservice.TechnicalReportActivity;
import com.glory.brepda.adapter.LotSubmissionhisAdapter;
import com.glory.brepda.adapter.SFCStockingAdapter;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.callback.CustomDialogEntityCallBack;
import com.glory.brepda.entity.EqpBody;
import com.glory.brepda.entity.EqpEntity;
import com.glory.brepda.entity.EqpInfoEntity;
import com.glory.brepda.entity.EquipMentEntity;
import com.glory.brepda.entity.LotInfoEntity;
import com.glory.brepda.entity.SFCStockingEntity;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.LotUtils;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import butterknife.BindView;
import butterknife.OnClick;

public class BreEFCCleanRecordActivity extends BaseActivity {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.etEqpid)
    FreeUI_ClearEditText etEqpid;
    @BindView(R.id.tvLocation)
    TextView tvLocation;
    @BindView(R.id.cbcleanclass)
    CheckBox cbcleanclass;
    @BindView(R.id.cbcleaneqp)
    CheckBox cbcleaneqp;
    @BindView(R.id.cbcleanvacuum)
    CheckBox cbcleanvacuum;
    @BindView(R.id.llMain)
    LinearLayout llMain;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_bre_efc_cleanrecord;
    }

    @Override
    protected void initView() {
        String title = getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY);
        tvTitle.setText(title);
        setMainLayout(llMain);

        initEdit(etEqpid, s -> {

            FreeUI_EntityCallBack<BaseResponseBean<EqpInfoEntity>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<EqpInfoEntity>>
                    ("正在查询设备信息", new TypeToken<BaseResponseBean<EqpInfoEntity>>() {
                    }.getType(), getSupportFragmentManager(), BreEFCCleanRecordActivity.this) {

                @Override
                public void onSuccess(Response<BaseResponseBean<EqpInfoEntity>> response) {
                    super.onSuccess(response);
                    if (response.body().isSuccess(BreEFCCleanRecordActivity.this, true, getSupportFragmentManager())) {
                        tvLocation.setText(response.body().getResponse().getBody().getEQUIPMENT().getLOCATION());
                    }
                }

                @Override
                public void onError(Response<BaseResponseBean<EqpInfoEntity>> response) {
                    super.onError(response);
                    loadError(response.getException(), "BREQUERYEQP");
                }
            };

            JsonObject map = new JsonObject();
            map.addProperty("ACTIONTYPE", "EQPBYID");
            EquipMentEntity equipMentEntity = new EquipMentEntity();
            equipMentEntity.setEQUIPMENTID(s);
            map.add("EQUIPMENT", new JsonParser().parse(new Gson().toJson(equipMentEntity)).getAsJsonObject());
            NetUtils.requestPostNet("IF.BREQUERYEQP", "Common", BreEFCCleanRecordActivity.this, map, callBack);
        });
    }

    @OnClick({R.id.tvBaseSubmit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvBaseSubmit:
                submit();
                break;
        }
    }

    private void submit(){

        if(getText(etEqpid).equals("")){
            showToast("请先扫描设备信息", false);
            return;
        }

        FreeUI_EntityCallBack<BaseResponseBean<SFCStockingEntity>> callBack = new FreeUI_DialogEntityCallBack<BaseResponseBean<SFCStockingEntity>>
                (new TypeToken<BaseResponseBean<SFCStockingEntity>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess(Response<BaseResponseBean<SFCStockingEntity>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getApplicationContext(), true, getSupportFragmentManager())) {

                    showToast("记录成功", true);

                    clean();
                    etEqpid.requestFocus();
                }
            }

            @Override
            public void onError(Response<BaseResponseBean<SFCStockingEntity>> response) {
                super.onError(response);
                loadError(response.getException(), "BRE_NONPAPER");

            }
        };
        JsonObject map = new JsonObject();
        map.addProperty("ACTIONTYPE", "EFC_CLEANRECORD");
        map.addProperty("EQP_ID", getText(etEqpid));
        map.addProperty("EQP_DESCRIPTION", tvLocation.getText().toString());
        map.addProperty("CLEAN_CHANGECLASS", cbcleanclass.isChecked()?"Y":"");
        map.addProperty("CLEAN_EQP", cbcleaneqp.isChecked()?"Y":"");
        map.addProperty("CLEAN_VACUUM", cbcleanvacuum.isChecked()?"Y":"");
        NetUtils.requestPostNet("IF.BRE_NONPAPER", "Common", BreEFCCleanRecordActivity.this, map, callBack);
    }

    public void clean(){
        etEqpid.setText("");

    }

    @Override
    protected void initData() {

    }

}